package com.xinke.edu.mypetadoption.net;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class RetrofitUtil {
    public static ApiService getApi(){
        HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        OkHttpClient client=new OkHttpClient().newBuilder()
                .addInterceptor(loggingInterceptor)
                .build();
        Retrofit retrofit=new Retrofit.Builder()
                .baseUrl(ApiService.BaseURL)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
                .build();
        ApiService getApi= retrofit.create(ApiService.class);
        return getApi;
    }
    
    // 提供与getApi()相同功能的方法，供其他地方使用
//    public static ApiService getApiService(){
//        HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor();
//        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
//
//        OkHttpClient client=new OkHttpClient().newBuilder()
//                .addInterceptor(loggingInterceptor)
//                .build();
//        Retrofit retrofit=new Retrofit.Builder()
//                .baseUrl(ApiService.BaseURL)
//                .client(client)
//                .addConverterFactory(GsonConverterFactory.create())
//                .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
//                .build();
//        ApiService apiService= retrofit.create(ApiService.class);
//        return apiService;
//    }
}
